local io = {}
local async

local install
install = function(io, s, ...)
	if s == nil then return end
	s._io = io
	install(io, ...)
end

local installed
installed = function(s, ...)
	if s == nil then return false end
	return s._io ~= nil or installed(...)
end

io.install_default = function(async_instance)
	local stream = require[[stream]]
	local state = require[[state]]
	io.install(async_instance, stream, state)
end

io.install = function(async_instance, ...)
	if installed(...) then error("attempt to install multiple io") end
	install(io, ...)
	async = async_instance
end

io.listen_button_press = function(listener)
	async.on_button_press(listener)
end

io.timeout = function(listener, duration)
	async:timeout(listener, duration)
end

io.now = function()
	return async:now()
end

return io

